package org.rambadger.command.representation;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import org.mongojack.Id;
import org.mongojack.MongoCollection;
import org.rambadger.command.validation.UrlIdentifier;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@MongoCollection(name = "assignments")
public class Assignment {
    public static class AssignmentId {
        @UrlIdentifier @NotNull
        @JsonProperty String platformId;

        @UrlIdentifier @NotNull
        @JsonProperty String assignmentId;

        AssignmentId() {}

        public AssignmentId(String platformId, String assignmentId) {
            this.platformId = platformId;
            this.assignmentId = assignmentId;
        }

        public String getPlatformId() {
            return platformId;
        }

        public String getAssignmentId() {
            return assignmentId;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof AssignmentId)) return false;

            AssignmentId that = (AssignmentId) o;

            if (!assignmentId.equals(that.assignmentId)) return false;
            if (!platformId.equals(that.platformId)) return false;

            return true;
        }

        @Override
        public int hashCode() {
            int result = platformId.hashCode();
            result = 31 * result + assignmentId.hashCode();
            return result;
        }
    }

    @Id @NotNull
    @JsonProperty AssignmentId assignmentId;

    @Length(max = 64) @NotBlank
    @JsonProperty String assignmentName;

    @Length(max = 4096) @NotBlank
    @JsonProperty String description;

    @Min(0) @JsonProperty int submissionPoints;
    @Min(0) @JsonProperty int reviewPoints;

    @JsonProperty String associatedTrack;

    Assignment() {}

    public Assignment(String platformId, String assignmentId, String assignmentName, String description, int submissionPoints, int reviewPoints){
        this.assignmentId =  new AssignmentId(platformId, assignmentId);
        this.assignmentName = assignmentName;
        this.description = description;
        this.submissionPoints = submissionPoints;
        this.reviewPoints = reviewPoints;
        this.associatedTrack = null;
    }

    public Assignment(String platformId, String assignmentId, String assignmentName, String description, int submissionPoints, int reviewPoints, String associatedTrack){
        this.assignmentId =  new AssignmentId(platformId, assignmentId);
        this.assignmentName = assignmentName;
        this.description = description;
        this.submissionPoints = submissionPoints;
        this.reviewPoints = reviewPoints;
        this.associatedTrack = associatedTrack;
    }

    public AssignmentId getAssignmentId() {
        return assignmentId;
    }

    public String getAssignmentName() {
        return assignmentName;
    }

    public void setAssignmentName(String assignmentName) {
        this.assignmentName = assignmentName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getSubmissionPoints() {
        return submissionPoints;
    }

    public void setSubmissionPoints(int submissionPoints) {
        this.submissionPoints = submissionPoints;
    }

    public int getReviewPoints() {
        return reviewPoints;
    }

    public void setReviewPoints(int reviewPoints) {
        this.reviewPoints = reviewPoints;
    }

    public String getAssociatedTrack() {
        return associatedTrack;
    }

    public void setAssociatedTrack(String associatedTrack) {
        this.associatedTrack = associatedTrack;
    }
}
